package com.controller;

import com.util.QiNiuYunUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import living.com.domain.QiNiuTokenResult;
import living.com.result.ApiResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/2/11 17:30
 */
@Api(tags = "问题文件请求处理类")
@RestController
@RequiredArgsConstructor
public class IssueFileController {
   private final QiNiuYunUtils qiNiuYunUtils;
   @ApiOperation("问题图片上传凭证获取")
   @PostMapping("/issue_pics")
   public ApiResult<List<QiNiuTokenResult>> getUploadPicsToken(@ApiParam("上传图片的数量")@RequestParam(defaultValue = "1") Integer pic_sum)
   {
      try {
         return ApiResult.success(qiNiuYunUtils.getTokenResults(pic_sum, QiNiuYunUtils.File_Type.ISSUE_IMG));
      } catch (Exception e) {
       throw new IllegalArgumentException("七牛云文件上传凭证获取出错");
      }
   }

   @ApiOperation("问题视频上传凭证获取")
   @PostMapping("/issue_videos")
   public ApiResult<QiNiuTokenResult> getUploadVideoToken()
   {
      try {
         return ApiResult.success(qiNiuYunUtils.getTokenResult(QiNiuYunUtils.File_Type.ISSUE_VIDEO.getFilePrefix()));
      } catch (Exception e) {
         throw new IllegalArgumentException("七牛云文件上传凭证获取出错");
      }
   }
}
